package wxk.interview.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/7.
 * @since 2.2
 */
@WebServlet(name = "MyRedirectServlet",urlPatterns = "/myRedirectServlet")
public class MyRedirectServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1.设置状态302,进行重定向
        resp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
        resp.setHeader("Location","http://www.baidu.com");

        // 2.直接使用resp的sendRedirect()方法
        //resp.sendRedirect("/mySimpleWithAnnotationServlet");
    }
}
